<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
	String categoryId = input.getDesc("category_id", "-1");
	List<Integer> caseIds = QBuilder.db("basedb").select("case_id").from("visit_link").where(new Where("cate_id =", categoryId).and("status = ", STATUS_ENABLE)).query().getResultObj();
	String index = "-1";
	if (isEmpty(caseIds)) {
        msg = new Message(30041, "暂无随访模板");
        Tools.encryptPrint(out, msg);
        return;
    }
	for (int i = 0; i < caseIds.size(); i++) {
		index += "," + caseIds.get(i);
	}
	List<Map> templates =  QBuilder.db("basedb").select("new map(id as template_id, template_name as title, template_type as detail)").from("visit_template").where(new Where("id in("+ index +")").and("status = ", STATUS_ENABLE).and("category=0")).order("id", "asc").query().getResultObj();
	List<Integer> myTemplates =  QBuilder.db("basedb").select("oid").from("visit_template").where(new Where("status = ", STATUS_ENABLE).and("category=", 1).and("uid=", token.getUid())).query().getResultObj();
	for (Map map:templates) {
		map.put("added", 0);
		Integer id = (Integer)map.get("template_id");
		if (myTemplates.contains(id))
			map.put("added", 1);
	}
	if (isEmpty(templates)) {
        msg = new Message(30041, "暂无随访模板");
    }
    msg.put("data", templates);
    Tools.encryptPrint(out, msg);
%>